define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_myagent(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"issue_type": "3","store": [' +
					'{"store_id": "001","store_name": "世达","credit_line": 5000,"brand": [' +
					'{"id": "001","name": "世达"},' +
					'{"id": "002","name": "博士"}' +
					'],"image": "img/upload/pro-img01.jpg","contact_name": "张三","contact_mobile": "18912345678","region": [' +
					'{"region": "上海"},' +
					'{"region": "北京"}],"store_cat": [' +
					'{"store_cat_name": "五金类"},' +
					'{"store_cat_name": "非五金类"}],"company_profile": "专营各类五金"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_delete(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		//返回信息
		return {
			//列表
			my_agent: function(nPage,callback,calldone) {
				Http.post({
					method: 'member.agenter.getlist',
					pagelimit: 10,
					nPage: nPage
				},
				function(result) {
					//请求成功
					if(callback) {
						callback(get_data_myagent(result).result);
					}
				},
				function(e) {
					//请求异常
				},
				function() {
					if(calldone)
						calldone();
				})
			},
			//删除我的代理商
			delete_agent: function(store_id, callback) {
				Http.post({
					method: 'member.agenter.delete',
					store_id: store_id
				}, function(result) {
					if(callback)
						callback(get_data_delete(result));
				}, function(e) {

				}, function() {

				});
			}


		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Myagent", factory);
});